"""
    Software : PyCharm
    File     : response.py
    Time     : 2021/5/24 18:21
    Author   : Pontoon
    describe :
"""
from rest_framework.response import Response
from rest_framework.status import HTTP_200_OK


class APIResponse(Response):
    def __init__(self, code=1, msg='success', result=None,
                 status=HTTP_200_OK, headers=None, content_type=None,
                 exception=False):
        """
        :param code: 1: 成功, 2: 失败
        :param msg: 信息提示
        :param result: 校验结果
        :param status: 状态码
        :param headers: 响应头s
        :param content_type:
        """
        data = {
            'code': code,
            'msg': msg
        }
        if result:
            data['result'] = result
        """
        data: {
            'code': 1,
            'msg': 'success'
            'result': {
                serializer.data
            }
        }
        """
        super().__init__(data=data, status=status, headers=headers,
                         content_type=content_type, exception=exception)
